package cn.tedu.charging.order.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqttProducer {
    @Autowired
    private MqttClient mqttClient;
    public Boolean send(String topic,String message){
        Boolean success = false;
        try {
            mqttClient.publish(topic,message.getBytes(),0,false);
            success = true;
        } catch (MqttException e) {
            log.error("给emqx消息发送失败,Topic:{},消息：{}",topic,message,e);
        }
        return success;
    }
}
